// AnsiScreen.h: interface for the CAnsiScreen class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ANSISCREEN_H__E90A0F8D_4ED6_4B2E_93DE_0241B47404F5__INCLUDED_)
#define AFX_ANSISCREEN_H__E90A0F8D_4ED6_4B2E_93DE_0241B47404F5__INCLUDED_

#include "IAnsiScreen.h"
#include "AnsiAttribute.h"
#include "IAnsiScreenEvents.h"
#include "IScreenInfo.h"

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class CAnsiScreen : public IAnsiScreen, public IScreenInfo
{
protected:
	CPoint m_ptCaret;
	CPoint m_ptSavedCaret;
	CSize m_size;

	CAnsiAttribute m_curAttr;
	CAnsiAttribute **m_attrs;
	char **m_chars;
	BYTE **m_effects;

	IAnsiScreenEvents *m_pEvents;
	int m_changeCounter;

protected:
	int getSafeX(int x);
	int getSafeY(int y);
	void release();
	void fireOnChange(int x1, int y1, int x2, int y2, BOOL addChangeCounter = TRUE);
	void fireOnCaretMove();
	void gotoNextLine();

public:
	virtual void GotoXY(int x, int y);
	virtual void MoveUp(int offset);
	virtual void MoveDown(int offset);
	virtual void MoveLeft(int offset);
	virtual void MoveRight(int offset);
	virtual void SaveCursor();
	virtual void UnsaveCursor();
	
public:
	virtual void ResetAttribute();
	virtual void SetForecolor(ANSI_COLOR color);
	virtual void SetBackcolor(ANSI_COLOR color);
	virtual void SetHighlight(BOOL bHighlight);
	virtual void SetUnderline(BOOL bUnderline);
	virtual void SetBlink(BOOL bBlink);
	virtual void SetInverse(BOOL bInverse);

public:
	virtual void SetSize(int cols, int rows);
	virtual void Erase(EraseType type);

	virtual void PutC(char c);
	virtual void SetCursor(HCURSOR hCursor);
	virtual void InsertLine(int lineCount);

	virtual void Update();

public:
	CSize GetSize();
	CPoint GetCaretPos();
	char** GetChars();
	CAnsiAttribute** GetAttrs();
	void RegisterEvents(IAnsiScreenEvents *pEvents);
	int GetChangeCounter();
	BYTE** GetEffects();

public:
	virtual void SetEffect(int x, int y, BYTE effect);
	virtual BYTE GetEffect(int x, int y);
	
public:
	CAnsiScreen();
	virtual ~CAnsiScreen();

//test
public:
	CString GetScreenText();
};

#endif // !defined(AFX_ANSISCREEN_H__E90A0F8D_4ED6_4B2E_93DE_0241B47404F5__INCLUDED_)
